package po;

import exception.InputNotRegularException;
import java.io.Serializable;

public class SalePolicyPO implements Serializable{
	private static final long serialVersionUID = 713317226076946037L;
	double rate;
	
	public void setRate(double r) throws InputNotRegularException{
		if(isValid(r))
			this.rate=r;
		else
			throw new InputNotRegularException("Rate must be between 0 and 1!");
	}
	
	public SalePolicyPO(double rate){
		this.rate=rate;
	}
	
	public int getPoints(double expense){
		return (int)(expense*this.rate);
	}	
	
	public double getRate(){
		return this.rate;
	}
	
	private boolean isValid(double r){
		if(0<=r&&r<=1)
			return true;
		return false;
	}
}
